//
//  ZZMainController.swift
//  SinaWeibo
//
//  Created by QUAN on 15/11/9.
//  Copyright © 2015年 QUAN. All rights reserved.
//

import UIKit

class ZZMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = ZZMainTabBar()
        
        //KVC赋值
        setValue(mainTabBar, forKey: "tabBar")
        
        //添加子控制器
        addChildViewControllers()
        
        //加号按钮注册点击事件
        mainTabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    func composeDidClick() {
        print(__FUNCTION__)
    }
    
    
    func addChildViewControllers() {
        
        addChildViewController(ZZHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(ZZMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(ZZDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(ZZProffileViewController(), imageName: "tabbar_profile", title: "我")
        
        
    }
    
    private func addChildViewController(childController: UIViewController, imageName: String, title: String) {
     
        childController.title = title
        
        childController.tabBarItem.image = UIImage(named: imageName)
        
        //添加导航控制器
        let nav = ZZBaseNavViewController(rootViewController: childController)
        addChildViewController(nav)
        
    }
    
}
